package com.hunttown.mes.manage.service;

import com.hunttown.mes.rpc.api.TransactionRpcService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * created by wangjunfu on 2020-05-08
 */
@Service
public class TransactionService {
    private final static Logger logger = LoggerFactory.getLogger(TransactionService.class);

    private final TransactionRpcService rpcService;
    private final TransportUserManageService userService;

    @Autowired
    public TransactionService(TransactionRpcService rpcService, TransportUserManageService userService) {
        this.rpcService = rpcService;
        this.userService = userService;
    }

    public Integer createApplyWithout(String businessName, String tableName, Integer recordId, Integer createPeople, Map<String, String> map) {
        return rpcService.createApplyWithout(businessName, tableName, recordId, createPeople, map);
    }

    public Boolean insertWfLine(Integer businessId, Integer applyId, Integer createPeople, Map<String, String> map) {
        return rpcService.insertWfLine(businessId, applyId, createPeople, map);
    }

    public void setExector(Integer applyId, Map<Integer, Integer> replaceMap) {
        rpcService.setExector(applyId, replaceMap);
    }

    public void setManageApply(Integer applyId, Integer nodeSort, Integer isAuto) {
        rpcService.setManageApply(applyId, nodeSort, isAuto);
    }

    //新版：approvel 改为 userId，addApprove也改为userId（controller较多，service修改）
    public Boolean approvelApply(Integer id, Integer status, String remark, Integer approvel, Integer addApprove, Integer backLineId) {
        //通过管理员ID获取用户ID
        approvel = userService.getUserIdByAdminId(approvel);

        return rpcService.approvelApply(id, status, remark, approvel, addApprove, backLineId);
    }

    //新版：adminId 改为 userId
    public void autoApply(Integer businessId, Integer applyId, Integer nodeSign, Integer adminId) {
        //通过管理员ID获取用户ID
        adminId = userService.getUserIdByAdminId(adminId);

        rpcService.autoApply(businessId, applyId, nodeSign, adminId);
    }

    //新版：adminId 改为 userId
    public void autoApply(Integer businessId, Integer applyId, Integer nodeSign, String remark, Integer adminId) {
        //通过管理员ID获取用户ID
        adminId = userService.getUserIdByAdminId(adminId);

        rpcService.autoApply(businessId, applyId, nodeSign, remark, adminId);
    }

    //新版：adminId 改为 userId
    public void autoApplyFirstNode(Integer applyId, Integer status, Integer adminId) {
        //通过管理员ID获取用户ID
        adminId = userService.getUserIdByAdminId(adminId);

        rpcService.autoApplyFirstNode(applyId, status, adminId);
    }

    //新版：adminId 改为 userId
    public void autoApplyCurrNode(Integer applyId, Integer status, Integer adminId) {
        //通过管理员ID获取用户ID
        adminId = userService.getUserIdByAdminId(adminId);

        rpcService.autoApplyCurrNode(applyId, status, adminId);
    }
}
